// pages/detectFail/detectFail.js

var originalImagePath;

Page({

  data: {
    reason: "",
    imageData: "",
    imageHeight: 0,
    imageWidth: 0,
  },

  onLoad: function (options) {
    originalImagePath = options.originalImagePath;
    let fs = wx.getFileSystemManager();
    let data = fs.readFileSync(originalImagePath, 'base64', 0);
    this.drawImage(data);
    this.setData({
      reason: options.reason
    })
  },

  drawImage(imageData) {
    wx.getImageInfo({
      src: originalImagePath,
      success: (res) => {
        console.log(res);
        if ((res.width / res.height) > (460 / 540)) {
          let imageWidth = 230;
          let imageHeight = res.height / res.width * imageWidth;
          this.setData({
            imageWidth,
            imageHeight,
            imageData: `data:image/${res.type};base64,${imageData}`
          })
        } else {
          let imageHeight = 270;
          let imageWidth = res.width / res.height * imageHeight;
          this.setData({
            imageWidth,
            imageHeight,
            imageData: `data:image/${res.type};base64,${imageData}`
          })
        }
      }
    })
  },

  reTake() {
    wx.navigateBack();
  },

  backHome() {
    wx.navigateBack({
      delta: 1000,
    })
  }

})